/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.lps.client.controller;

import com.brs.client.Client;
import com.brs.client.view.ComplaintManagerPanel;
import com.brs.client.view.DispatchManagerPanel;
import com.brs.client.view.OrderManagerPanel;
import com.brs.client.view.ProductManagerPanel;
import com.brs.client.view.UserManagerPanel;
import com.brs.model.Department;
import com.brs.model.User;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/**
 *
 * @author phichidev
 * using init component for Main Frame
 */
public class MainFeatureController {

    private javax.swing.JPanel panelMain;
    private javax.swing.JMenu accountMenu;
    private javax.swing.JMenu adminMenu;
    private javax.swing.JMenu callcenterMenu;
    private javax.swing.JMenu dispatchMenu;
    private javax.swing.JMenu orderMenu;
    private javax.swing.JMenu technicalMenu;

    private JMenuItem userMenuItem = new JMenuItem("User Manager");
    private JMenuItem productMenuItem = new JMenuItem("Product Manager");
    private JMenuItem orderMenuItem = new JMenuItem("Order Manager");
    private JMenuItem dispatchMenuItem = new JMenuItem("Dispatch Manager");
    private JMenuItem complaintMenuItem = new JMenuItem("Complaint Manager");
    /**
     * Constructor
     * @param panelMain
     * @param accountMenu
     * @param adminMenu
     * @param callcenterMenu
     * @param dispatchMenu
     * @param orderMenu
     * @param technicalMenu
     */
    public MainFeatureController(JPanel panelMain, JMenu accountMenu, JMenu adminMenu, JMenu callcenterMenu, JMenu dispatchMenu, JMenu orderMenu, JMenu technicalMenu) {
        this.panelMain = panelMain;
        this.accountMenu = accountMenu;
        this.adminMenu = adminMenu;
        this.callcenterMenu = callcenterMenu;
        this.dispatchMenu = dispatchMenu;
        this.orderMenu = orderMenu;
        this.technicalMenu = technicalMenu;
    }
    
    /**
     * Add action listener for component
     */
    public void initFeatures() {
        userMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                UserManagerPanel userManagerPanel = new UserManagerPanel();
                panelMain.removeAll();
                panelMain.add(userManagerPanel, java.awt.BorderLayout.CENTER);
                panelMain.validate();
            }
        });
        productMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                ProductManagerPanel productPanel = new ProductManagerPanel();
                panelMain.removeAll();
                panelMain.add(productPanel, java.awt.BorderLayout.CENTER);
                panelMain.validate();
            }
        });
        orderMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                OrderManagerPanel orderPanel =new OrderManagerPanel();
                panelMain.removeAll();
                panelMain.add(orderPanel,java.awt.BorderLayout.CENTER);
                panelMain.validate();
            }
        });
        dispatchMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                DispatchManagerPanel dispatchPanel = new DispatchManagerPanel();
                panelMain.removeAll();
                panelMain.add(dispatchPanel,java.awt.BorderLayout.CENTER);
                panelMain.validate();
            }
        });
        complaintMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                ComplaintManagerPanel complaintPanel =new ComplaintManagerPanel();
                panelMain.removeAll();
                panelMain.add(complaintPanel,java.awt.BorderLayout.CENTER);
                panelMain.validate();
            }
        });
        User currentUser = Client.getInstance().getCurrentUser();
        //System.out.println("currentUser.getDepartment(): " + currentUser.getDepartment());
        switch (currentUser.getDepartment()) {
            case Department.ADMIN:
                initAdminComponent();
                break;
            case Department.ACCOUNT:
                initAccountComponent();
                break;
            case Department.CALLCENTRE:
                initCallCenterComponent();
                break;
            case Department.DISPATCHER:
                initDispatchComponent();
                break;
            case Department.ORDER:
                initOrderComponnet();
                break;
            case Department.TECHNICIAN:
                initTechnicalComponent();
                break;
        }
    }
    /**
     * Init menu item for Admin menu
     */
    private void initAdminComponent() {
        adminMenu.setEnabled(true);
        adminMenu.add(userMenuItem);
        adminMenu.add(productMenuItem);
        adminMenu.add(complaintMenuItem);
        adminMenu.add(orderMenuItem);
    }
    /**
     * Init menu item for Account menu
     */
    private void initAccountComponent() {
        accountMenu.setEnabled(true);
        accountMenu.add(orderMenuItem);
    }
    /**
     * Init menu item for Callcentre menu
     */
    private void initCallCenterComponent() {
        callcenterMenu.setEnabled(true);
        callcenterMenu.add(orderMenuItem);
        callcenterMenu.add(complaintMenuItem);
        callcenterMenu.add(productMenuItem);
    }
    /**
     * Init menu item for Disaptch menu
     */
    private void initDispatchComponent() {
        dispatchMenu.setEnabled(true);
        dispatchMenu.add(dispatchMenuItem);
    }
    /**
     * Init menu item for Order menu
     */
    private void initOrderComponnet() {
        orderMenu.setEnabled(true);
        orderMenu.add(orderMenuItem);
        orderMenu.add(productMenuItem);
    }
    /**
     * Init menu item for Technical menu
     */
    private void initTechnicalComponent() {
        technicalMenu.setEnabled(true);
        technicalMenu.add(complaintMenuItem);
    }
}
